﻿package com.schimanek.controls 
{
	import flash.display.DisplayObject;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	
	/**
	 * ...
	 * @author G
	 */
	public class KeyControls 
	{		
		public var leftPressed		:Boolean
		public var upPressed		:Boolean
		public var rightPressed		:Boolean
		public var downPressed		:Boolean
		public var spacePressed		:Boolean
		public var enterPressed		:Boolean
		
		public function KeyControls(target:DisplayObject) 
		{
			target.addEventListener(KeyboardEvent.KEY_DOWN, onKey);
			target.addEventListener(KeyboardEvent.KEY_UP, onKey);
		}
		
		private function onKey(e:KeyboardEvent):void 
		{	
			
			var isDown:Boolean = e.type == KeyboardEvent.KEY_DOWN;			
			switch(e.keyCode) {
				case Keyboard.LEFT:
					leftPressed = isDown;
					break;
				case Keyboard.UP:
					upPressed = isDown;
					break;
				case Keyboard.RIGHT:
					rightPressed = isDown;
					break;
				case Keyboard.DOWN:
					downPressed = isDown;
					break;
				case Keyboard.SPACE:
					spacePressed = isDown;
					break;
				case Keyboard.ENTER:
					enterPressed = isDown;
					break;				
				
			}
			
		}
		
		
	}
	
}